<?
    require_once("iDB.php");
    
    class MySQLDBManager {
        private $_resource = null;
        private $_last_query = null;
        
        function __construct($dbhost,$dbuser,$dbpass,$db) {
            $this->_resource = mysql_connect($dbhost,$dbuser,$dbpass) or die("ERROR: " . mysql_error($this->_resource));
            mysql_select_db($db,$this->_resource) or DBM::Error("USE $db;");
        }
        function IsConnected() {
            return !($this->_resource == null);
        }
        function Query($query) {
            $result = mysql_query($query,$this->_resource) or die($query . "<br />" . mysql_error($this->_resource));
            $this->_last_query = $query;
            return $result;
        }
        function QueryHasRows($query) {
            return ($this->CountRows($query) > 0);
        }
	function AffectedRows() {
            return mysql_affected_rows();
	}
        function CountRows($query) {
            $result = $this->Query($query);
            return mysql_num_rows($result);
        }
        function LastInsertID() {
            return mysql_insert_id();
        }
        function FetchRow($query = null) {
            $result = $this->_last_result_set;
            if ($query != null || $query != $this->_last_query) $result = $this->Query($query);
            return mysql_fetch_assoc($result);
        }
        function FetchAllRows($query) {
            $result = $this->Query($query);
            $rows = array();
            while ($row = mysql_fetch_assoc($result)) $rows[] = $row;
            
            return $rows;
        }
    }
?>
